package eu.goldenak.ircbot;

/**
 * This class represents an IRC channel, with key, if there is one needed to 
 * enter it.
 */
public class IrcChannel {
	/**
	 * The channel name.
	 */
	private String m_sName;
	
	/**
	 * The key needed to get in, if needed.
	 */
	private String m_sKey;
	
	/**
	 * Configure the IRC channel without a key.
	 */
	public IrcChannel (String sName) {
		m_sName = sName;
	}
	
	/**
	 * Configure the IRC channel with a key.
	 */
	public IrcChannel (String sName, String sKey) {
		m_sName = sName;
		m_sKey  = sKey;
	}
	
	/**
	 * This constructor can be used in combination with the configfile reader.
	 * This will accept a String that has been split into 1 or 2 pieces, where
	 * the first element is the channel name and the second (if present) the 
	 * key needed to enter it.
	 */
	public IrcChannel (String [] aChannelInfo) {
		m_sName = aChannelInfo [0];
		if (aChannelInfo.length > 1) {
			m_sKey = aChannelInfo [1];
		}
	}
	
	/**
	 * Returns the name for this channel.
	 */
	public String getName () {
		return m_sName;
	}
	
	/**
	 * Returns the key for this channel.
	 */
	public String getKey () {
		return m_sKey;
	}
	
	/**
	 * Returns true if this channel has a key.
	 */
	public boolean hasKey () {
		return m_sKey != null;
	}
	
	/**
	 * Same as toString().
	 */
	public int hashCode () {
		return getName ().toLowerCase ().hashCode ();
	}
	
	/**
	 * Improvements needed, channelkey.
	 */
	public boolean equals (Object pObject) {
		if (pObject instanceof IrcChannel) {
			String sChannel = ((IrcChannel) pObject).getName ();
			
			return sChannel.toLowerCase ().equals (getName ().toLowerCase ());
		}
		
		return false;
	}
	
	/**
	 * Same as equals.
	 */
	public String toString () {
		return m_sName;
	}
}